package com.example.activity.service;

import com.example.activity.dao.ActivityMapper;
import com.example.activity.entity.Activity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 14:06 2019/4/4
 */
@Service
public class ActivityServiceImpl implements ActivityService {

    private static final Integer DEFAULT_LIMIT = 2;
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public List<Activity> selectActivityPaginationList(Integer offset) {
        if (offset!=0){
            offset=offset-1;
        }
        List<Activity> activityList=activityMapper.selectActivityPaginationList(offset*DEFAULT_LIMIT,DEFAULT_LIMIT);
        return activityList;
    }

    @Override
    public int activityListCount() {
        return activityMapper.selectActivityListCount();
    }

    @Override
    public Activity selectActivityDetail(Long activityId) {
        return activityMapper.selectByPrimaryKey(activityId);
    }

    @Override
    public List<Activity> selectActivityListPage(int offset, int limit) {
        return activityMapper.selectActivityListPage(offset,limit);
    }

    @Override
    public int selectActivityPageCount() {
        return activityMapper.selectActivityPageCount();
    }

    @Override
    public void addActivity(Activity activity) {
        activity.setActivityCreateTime(new Date());
        activity.setActivityStatus(true);
        activityMapper.insert(activity);
    }

    @Override
    public void publishActivity(Activity activity) {
        activity.setActivityStatus(false);
        activityMapper.updateByPrimaryKeySelective(activity);
    }

    @Override
    public void deleteActivity(Activity activity) {
        activityMapper.deleteByPrimaryKey(activity.getActivityId());
    }
}
